package db.nio.worker;

import db.nio.handler.BackHandler;

import java.nio.channels.SelectionKey;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 后台员工(数据读取触发线程）
 * Created by daibin on 10/27/16.
 */
public class BackWorker extends Worker{


    /**
     * 员工
     * @param poolExecutor 线程池
     */
    public BackWorker(ThreadPoolExecutor poolExecutor){
        super(poolExecutor);
    }

    @Override
    public void work(SelectionKey selectionKey) {
        if (selectionKey.isReadable()) {

            //锁住读事件
            selectionKey.interestOps(selectionKey.interestOps() & ~SelectionKey.OP_READ);

            //开新线程进行读事件
            poolExecutor.execute(new BackHandler(selectionKey));
        }
    }
}
